﻿using System;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;

namespace project_phoenix.source
{
    abstract public class PlayableEntity : Entity
    {
        protected int mCurXp;
        protected string mHudImagePath;

    #region functions
        // Lets force the kids to override these
        abstract public void LevelUp();

        public void Spawn(Vector2 pos)
        {
            isAlive = true;
            position = pos;
        }

        public void SetupDefaultAnimations()
        {
            // add our animations
            animation.AddAnimation(new Animation(3, 100, 100, 3, Animation.animType.Idle, true));
            animation.AddAnimation(new Animation(3, 100, 100, 3, Animation.animType.Walking, true));
            animation.AddAnimation(new Animation(9, 100, 100, 3, Animation.animType.Attacking, false));
            animation.AddAnimation(new Animation(3, 100, 100, 3, Animation.animType.Blocking, false));
            animation.AddAnimation(new Animation(3, 100, 100, 3, Animation.animType.Dead, false));
            animation.AddAnimation(new Animation(3, 100, 100, 3, Animation.animType.Dying, false));
            animation.AddAnimation(new Animation(3, 100, 100, 3, Animation.animType.Hit, false));
            animation.AddAnimation(new Animation(3, 100, 100, 3, Animation.animType.Jumping, false));

            //default animation is the idle
            animation.PlayAnimation(Animation.animType.Idle);
        }

        public void LoadContent()
        {
            // only make this is we dont have an animation set already
            if(animation == null)
                animation = new AnimationManager("sprites\\testAnim");
        }

        public override void Draw()
        {
            if (isAlive == false)
                return;


            animation.Draw(position);
        }

        public override void Update(GameTime gameTime)
        {
            if (isAlive == false)
                return;

            Vector2 dir = new Vector2(0, 0);
            if (Facing == EntityFacing.Left)
                dir.X = -1;
            else
                dir.X = 1;

            // This is getting ugly - add delagates later!
            // for now if the attack state is on and the anim is done, change back to idle
            if (State == EntityState.Attacking && animation.Animation.IsDone)
            {
                animation.PlayAnimation(Animation.animType.Idle);
                State = EntityState.Idle;
            }


            // If we are attacking we arent necessarily holding the button down
            if (State == EntityState.Idle && State != EntityState.Attacking)
            {
                animation.PlayAnimation(Animation.animType.Idle);
            }

            // reset to idle (only if we arent doing one of these things: attacking, getting hit, jumping, etc)
            if (State != EntityState.Attacking)
            {
                State = EntityState.Idle;
            }

            // update our animation
            animation.UpdateAnimation(gameTime, dir);
        }

        public void MoveLeft()
        {
            if (State == EntityState.Attacking)
                return;
            position.X -= moveSpeed.X;
            Facing = EntityFacing.Left;
            State = EntityState.Walking;
            animation.PlayAnimation(Animation.animType.Walking);
        }

        public void MoveRight()
        {
            if (State == EntityState.Attacking)
                return;
            position.X += moveSpeed.X;
            Facing = EntityFacing.Right;
            State = EntityState.Walking;
            animation.PlayAnimation(Animation.animType.Walking);
        }

        public void MoveUp()
        {
            if (State == EntityState.Attacking)
                return;
            position.Y -= moveSpeed.Y;
            State = EntityState.Walking;
            animation.PlayAnimation(Animation.animType.Walking);
        }

        public void MoveDown()
        {
            if (State == EntityState.Attacking)
                return;
            position.Y += moveSpeed.Y;
            State = EntityState.Walking;
            animation.PlayAnimation(Animation.animType.Walking);
        }

        public void Attack()
        {
            State = EntityState.Attacking;
            animation.PlayAnimation(Animation.animType.Attacking);
        }

        public void StopMove()
        {
            animation.PlayAnimation(Animation.animType.Idle);
        }
    #endregion
    #region properties
        public float ExpPercent
        {
            get { return mCurXp; }//return (float)((float)mCurHealth / (float)mMaxHealth); }
        }

        public string HudImagePath
        {
            get { return mHudImagePath; }
        }
    #endregion


    }
}
